1 /*
2  * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
3  * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation version 2.1 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18  *
19  * Described at ISO/IEC 13818-1
20  */
21 
22 module libdvbv5_d.header;
23 
24 import libdvbv5_d.dvb_fe: dvb_v5_fe_parms;
25 
26 extern (C):
27 
28 /* ssize_t */
29 
30 /**
31  * @file header.h
32  * @ingroup dvb_table
33  * @brief Provides the MPEG TS table headers
34  * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1)
35  * @author Mauro Carvalho Chehab
36  * @author Andre Roth
37  *
38  * @par Bug Report
39  * Please submit bug reports and patches to linux-media@vger.kernel.org
40  */
41 
42 /**
43  * @struct dvb_ts_packet_header
44  * @brief Header of a MPEG-TS transport packet
45  * @ingroup dvb_table
46  *
47  * @param sync_byte			sync byte
48  * @param pid				Program ID
49  * @param transport_priority		transport priority
50  * @param payload_unit_start_indicator	payload unit start indicator
51  * @param transport_error_indicator	transport error indicator
52  * @param continuity_counter		continuity counter
53  * @param adaptation_field_control	adaptation field control
54  * @param transport_scrambling_control	transport scrambling control
55  * @param adaptation_field_length	adaptation field length
56  *
57  * @see http://www.etherguidesystems.com/Help/SDOs/MPEG/Semantics/MPEG-2/transport_packet.aspx
58  */
59 struct dvb_ts_packet_header
60 {
61     import std.bitmanip : bitfields;
62     align (1):
63 
64     ubyte sync_byte;
65 
66     union
67     {
68         align (1):
69 
70         ushort bitfield;
71 
72         struct
73         {
74             import std.bitmanip : bitfields;
75             align (1):
76 
77             mixin(bitfields!(
78                 ushort, "pid", 13,
79                 ushort, "transport_priority", 1,
80                 ushort, "payload_unit_start_indicator", 1,
81                 ushort, "transport_error_indicator", 1));
82         }
83     }
84 
85     mixin(bitfields!(
86         ubyte, "continuity_counter", 4,
87         ubyte, "adaptation_field_control", 2,
88         ubyte, "transport_scrambling_control", 2));
89 
90     /* Only if adaptation_field_control > 1 */
91     ubyte adaptation_field_length;
92     /* Only if adaptation_field_length >= 1 */
93     struct
94     {
95         import std.bitmanip : bitfields;
96         align (1):
97 
98         mixin(bitfields!(
99             ubyte, "extension", 1,
100             ubyte, "private_data", 1,
101             ubyte, "splicing_point", 1,
102             ubyte, "OPCR", 1,
103             ubyte, "PCR", 1,
104             ubyte, "priority", 1,
105             ubyte, "random_access", 1,
106             ubyte, "discontinued", 1));
107     }
108 }
109 
110 /**
111  * @struct dvb_table_header
112  * @brief Header of a MPEG-TS table
113  * @ingroup dvb_table
114  *
115  * @param table_id		table id
116  * @param section_length	section length
117  * @param syntax		syntax
118  * @param id			Table ID extension
119  * @param current_next		current next
120  * @param version		version
121  * @param section_id		section number
122  * @param last_section		last section number
123  *
124  * All MPEG-TS tables start with this header.
125  */
126 struct dvb_table_header
127 {
128     import std.bitmanip : bitfields;
129     align (1):
130 
131     ubyte table_id;
132 
133     union
134     {
135         align (1):
136 
137         ushort bitfield;
138 
139         struct
140         {
141             import std.bitmanip : bitfields;
142             align (1):
143 
144             mixin(bitfields!(
145                 ushort, "section_length", 12,
146                 ubyte, "one", 2,
147                 ubyte, "zero", 1,
148                 ubyte, "syntax", 1));
149         }
150     }
151 
152     ushort id;
153 
154     mixin(bitfields!(
155         ubyte, "current_next", 1,
156         ubyte, "version_", 5,
157         ubyte, "one2", 2)); /* TS ID */
158 
159     ubyte section_id; /* section_number */
160     ubyte last_section; /* last_section_number */
161 }
162 
163 // struct dvb_v5_fe_parms;
164 
165 /**
166  * @brief Initializes and parses MPEG-TS table header
167  * @ingroup dvb_table
168  *
169  * @param header pointer to struct dvb_table_header to be parsed
170  */
171 void dvb_table_header_init (dvb_table_header* header);
172 /**
173  * @brief Prints the content of the MPEG-TS table header
174  * @ingroup dvb_table
175  *
176  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
177  * @param header pointer to struct dvb_table_header to be printed
178  */
179 void dvb_table_header_print (
180     dvb_v5_fe_parms* parms,
181     const(dvb_table_header)* header);
182